﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Procenge.PortalVendas.Models;



namespace Procenge.PortalVendas.Controllers
{
    public class CompraController : Controller
    {
        //
        // GET: /Compra/

        ModelCompra contexto = new ModelCompra();

        public ActionResult Index()
        {
            return View(contexto.ListarCompra());
        }

        //
        // GET: /Compra/Details/5

        public ActionResult Details(int nf)
        {
            return View(contexto.BuscarCompraNf(nf));
        }

        //
        // GET: /Compra/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /Compra/Create

        [HttpPost]
        public ActionResult Create(Compra compra)
        {
            try
            {
                // TODO: Add insert logic here
                contexto.CriarCompra(compra);

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Compra/Edit/5

        public ActionResult Edit(int nf)
        {
            return View(contexto.BuscarCompraNf(nf));
        }

        //
        // POST: /Compra/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
                Compra compra = contexto.BuscarCompraNf(id);
                UpdateModel(compra);
                contexto.Salvar();

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Compra/Delete/5

        public ActionResult Delete(int id)
        {
            return View(contexto.BuscarCompraNf(id));
        }

        //
        // POST: /Compra/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
                contexto.RemoverCompra(id);

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
